package com.echo.echovividlive.controller;


import com.echo.echovividlive.common.UserThread;
import com.echo.echovividlive.domain.dto.ReportPageDTO;
import com.echo.echovividlive.domain.entity.Report;
import com.echo.echovividlive.domain.entity.Result;
import com.echo.echovividlive.service.IReportService;
import com.echo.echovividlive.utils.TimeUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiajunjie
 * @since 2024-10-22
 */
@RestController
@RequestMapping("/echo/report")
public class ReportController {

    @Resource
    private IReportService reportService;

    /**
     * 发布举报信息
     * @param report
     * @return
     */
    @PostMapping("/post")
    public Result post(@RequestBody Report report) {
        report.setSenderId(UserThread.getUserId());
        report.setCreateTime(TimeUtil.getCurrentTime());
        report.setStatus(false);
        reportService.save(report);
        return Result.success();
    }

    /**
     * 更新举报信息
     * @param report
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Report report) {
        reportService.updateById(report);
        return Result.success();
    }

    @PostMapping("/list")
    public Result list(@RequestBody ReportPageDTO pageDTO) {
        return reportService.pageList(pageDTO);
    }

    @GetMapping("/delete/{reportId}")
    public Result delete(@PathVariable Integer reportId) {
        reportService.removeById(reportId);
        return Result.success();
    }
}
